import java.io.IOException;
import java.util.Random;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mac
 * Date: 2022-08-14
 * Time: 17:19
 */
public class LogoicalCtol {
    //1.所有的代码，都是用逻辑控制实现的

    //2.逻辑控制语句内必须是bool表达式

    public static void main1(String[] args) {
        System.out.println("1");
        System.out.println("2");
        System.out.println("3");
        System.out.println("4");
    }

    //System.in代表从键盘输入输出 - 最好不要用输入 - 直接传参数不OK？
    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);//准备工作
        int n = scanner.nextInt();

        String str = scanner.nextLine();
        System.out.println(str);
        if (n % 2 == 0){
            System.out.println("偶数");
        } else {
            System.out.println("奇数");
        }
    }

    //3.先读整数在读字符串 - 出bug - 做项目好自为之
    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);//准备工作
        String str = scanner.nextLine();
        //String str = scanner.next();//遇到空格结束
        System.out.println(str);
    }

    //4.任何一行代码，有括号不要省略
    public static void main4(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int year = scanner.nextInt();
        if(year % 100 != 0 && year % 4 == 0 || year % 400 == 0){
            System.out.println(year+"是闰年！");
        } else{
            System.out.println(year+"不是闰年！");
        }
        scanner.close();
    }

    //5.java中，不能做Switch参数类型：
    //long float double boolean
    public static void main5(String[] args) {
        //byte a = 10;
        //short a = 10;
        //char a = 'f';
        //int a = 10;
        String a = "hello";
        //jdk1.5之后 ：枚举也可以作为switch参数
        switch(a){
            case "abcd":
                System.out.println("1");
                break;
            case "hello":
                System.out.println("2");
                break;
            default:
                System.out.println("参数不匹配");
                break;
        }
    }

    public static void main6(String[] args) {
        int i = 1;
        int sum = 0;
        while (i <= 10){
            sum += 1;
            i++;
        }
        System.out.println(sum);
    }

    public static void main7(String[] args) {
        while (true){
            System.out.println("false");
        }
    }

    public static void main8(String[] args) {
        int j = 1;
        int sum = 1;
        while (j <= 5) {
            int n = j;
            int i = 1;
            int ret = 1;
            while (i <= n) {
                ret *= i;
                i++;
            }
            sum += ret;
            j++;
        }
        System.out.println(sum);
    }

    //6.加上括号的好处！！！
    public static void main9(String[] args) {
        int k = 10;
        int j = 10;
        while (k > 0)
            System.out.println("abcd");
            while (j > 0)
                System.out.println("1234");
        System.out.println("12345");
        System.out.println("123456");
    }

    //break结束最近的循环
    public static void main10(String[] args) {
        int i = 1;
        while (i <= 10){
            if (i % 3 != 0){
                i++;
                continue;//结束本趟循环
            }
            System.out.println(i);
            i++;
        }
    }

    public static void main11(String[] args) {
        for (int i = 1; i <= 100; i++) {
            if (i % 15 != 0){
                i++;
                continue;
            } else{
                System.out.println(i);
                i++;
            }
        }
    }

    //foreach -- 增强for循环
    public static void main12(String[] args) {
        int sum = 0;
        for (int i = 0; i < 100; i++) {
            sum += i;
        }
        System.out.println(sum);
    }

    //for 死循环
    //数据类型的默认值是实际化成员变量
    public static void main13(String[] args) {
        for(;;){
            System.out.println("hello");
        }
    }

    public static void main14(String[] args) {
        int ret = 1;
        int sum = 0;
        for (int i = 1; i <= 5; i++) {
            ret *= i;
            sum += ret;
        }
        System.out.println(sum);
    }

    public static void main15(String[] args) {
        System.out.println("输出且换行");
        System.out.print("输出且不换行");
        System.out.printf("%d\n", 10);
    }

    //基本不会用这种输入方法
    public static void main16(String[] args) throws IOException {
        System.out.print("Enter a Char:");
        char i = (char) System.in.read();
        System.out.println("your char is :"+i);
    }

    //用字符串输入时尽量先读字符串再读整数，否则会吃掉回车
    public static void main17(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String cur = scanner.next();
        System.out.println(cur);//遇到空格结束，尽量用nextline
        //String str = scanner.nextLine();
        //System.out.println(str);
        int n = scanner.nextInt();
        System.out.println(n);
        //double d = scanner.nextDouble();
        //System.out.println(d);
        scanner.close();//跟fclose差不多
    }

    //循环读取N组数据 -- ctrl + d结束
    public static void main18(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()){
            int n = scanner.nextInt();
            System.out.println(n);
        }
    }

    //猜数字游戏

    public static void main(String[] args) {
        Random random = new Random();
        int rand = random.nextInt(50) + 50;//[0-100) - [1-101)
        System.out.println("rand" + rand);

        Scanner scanner = new Scanner(System.in);

        while (true){
            System.out.println("请输入你要猜的数字");
            int n = scanner.nextInt();
            if (n < rand){
                System.out.println("猜小了");
            } else if(n == rand){
                System.out.println("猜对了");
                break;
            } else {
                System.out.println("猜大了");
            }
        }
    }
}












































